package tech.yangzhijie.basic.design.patterns.creational.factory.simplefactory;

import java.util.Scanner;

public class SimpleFactoryTest {

    public static void main(String[] args) {
        try(Scanner scanner = new Scanner(System.in)) {
            String product = "";
            while (true){
                System.out.println("请输入你想要的产品: ");
                System.out.println("1: Laptop");
                System.out.println("2: GraphicsCard");
                System.out.println("3: 退出");
                String cmd = scanner.nextLine();
                if(cmd != null && !"".equals(cmd)){
                    if(cmd.equals("1")){
                        product = "Laptop";
                    }else if(cmd.equals("2")){
                        product = "GraphicsCard";
                    }else if(cmd.equals("3")){
                        return;
                    }else {
                        System.out.println("参数有误");
                        product = "iPhone";
                    }
                    SimpleFactory.getProduct(product).use();
                }
            }
        }
    }
}
